﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using QLKhachSan.DTO;
using System.Data.SqlClient;
using QLKhachSan.DAO;
using QLKhachSan.BUS;
using DevExpress.XtraEditors;

namespace QLKhachSan.GUI
{
    public partial class fBaoCao : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public fBaoCao()
        {
            InitializeComponent();
        }
        public static int soTien;
        public static DataTable duLieu;
        private fInBaoCao _fInBaoCao ;
        public static string thoiGian;
      
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Lập Báo Cáo Doanh Thu Tháng:  Từ " + dateTimePicker1.Text + " Đến " + dateTimePicker2.Text + "   Và In ", "Note !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                duLieu = DAO_PhieuThu.hienThiDanhSachPhieuThuKhoangThang(dateTimePicker1.Value.Month, dateTimePicker2.Value.Month, dateTimePicker1.Value.Year, dateTimePicker2.Value.Year);
                soTien = int.Parse(textBoxTien.Text);
                thoiGian = "Từ " + dateTimePicker1.Text + " Đến " + dateTimePicker2.Text ;
                this.Close();             
                _fInBaoCao = new fInBaoCao();
                _fInBaoCao.MdiParent = fMain.ActiveForm;
                _fInBaoCao.Show();
            }

        }

        private void fBaoCao_Load(object sender, EventArgs e)
        {
            soTien = 0;
            duLieu = null;            
            int tien = 0;
            textBoxTien.Enabled = false;            
            DataTable dta_pt = DAO_PhieuThu.hienThiDanhSachPhieuThuKhoangThang(dateTimePicker1.Value.Month, dateTimePicker2.Value.Month, dateTimePicker1.Value.Year, dateTimePicker2.Value.Year);
            dataGridViewPT.DataSource = dta_pt;

            for (int i = 0; i < dta_pt.Rows.Count; i++ )
            {
                tien += int.Parse(dta_pt.Rows[i]["TienTraTruoc"].ToString()) + int.Parse(dta_pt.Rows[i]["TienPhaiTra"].ToString());
            }
            textBoxTien.Text = tien.ToString();
        }


        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            dateTimePicker2.MinDate = dateTimePicker1.Value;
            fBaoCao_Load(sender, e); 
        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            fBaoCao_Load(sender, e); 
        }
    }
}